﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LanhuFx.Identity
{
    public static class Conver
    {
        public static string[] PermissionTypeToArray(this int value)
        {
            List<string> data = new List<string>();

            if ((value & (int)PermissionType.Seach) == (int)PermissionType.Seach)
                data.Add("Seach");

            if ((value & (int)PermissionType.Add) == (int)PermissionType.Add)
                data.Add("Add");

            if ((value & (int)PermissionType.Edit) == (int)PermissionType.Edit)
                data.Add("Edit");

            if ((value & (int)PermissionType.Delete) == (int)PermissionType.Delete)
                data.Add("Delete");

            return data.ToArray();
        }

        public static int PermissionTypeToArray(this string[] value)
        {
            int PermissionData = (int)PermissionType.None;
            foreach (var item in value)
            {
                switch (item)
                {
                    case "Seach":
                        PermissionData = PermissionData | (int)PermissionType.Seach;
                        break;
                    case "Add":
                        PermissionData = PermissionData | (int)PermissionType.Add;
                        break;
                    case "Edit":
                        PermissionData = PermissionData | (int)PermissionType.Edit;
                        break;
                    case "Delete":
                        PermissionData = PermissionData | (int)PermissionType.Delete;
                        break;
                }
            }
            return PermissionData;
        }
    }
}
